
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>路由和侧边栏 · introduce</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gj">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../index.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="env.html" />
    
    
    <link rel="prev" href="webpack.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    Vscode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="jsdoc.html">
            
                <a href="jsdoc.html">
            
                    
                    Jsdoc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="webpack.html">
            
                <a href="webpack.html">
            
                    
                    Webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5" data-path="router.html">
            
                <a href="router.html">
            
                    
                    路由和侧边栏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="cors.html">
            
                <a href="cors.html">
            
                    
                    跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="router-lazyload.html">
            
                <a href="router-lazyload.html">
            
                    
                    路由懒加载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="icons.html">
            
                <a href="icons.html">
            
                    
                    图标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="i18n.html">
            
                <a href="i18n.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="eslint.html">
            
                <a href="eslint.html">
            
                    
                    ESLint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="permission.html">
            
                <a href="permission.html">
            
                    
                    权限验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="style.html">
            
                <a href="style.html">
            
                    
                    样式
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >路由和侧边栏</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x8DEF;&#x7531;&#x548C;&#x4FA7;&#x8FB9;&#x680F;">&#x8DEF;&#x7531;&#x548C;&#x4FA7;&#x8FB9;&#x680F;</h1>
<p>&#x8DEF;&#x7531;&#x548C;&#x4FA7;&#x8FB9;&#x680F;&#x662F;&#x7EC4;&#x7EC7;&#x8D77;&#x4E00;&#x4E2A;&#x540E;&#x53F0;&#x5E94;&#x7528;&#x7684;&#x5173;&#x952E;&#x9AA8;&#x67B6;&#x3002;</p>
<p>&#x672C;&#x9879;&#x76EE;&#x4FA7;&#x8FB9;&#x680F;&#x548C;&#x8DEF;&#x7531;&#x662F;&#x7ED1;&#x5B9A;&#x5728;&#x4E00;&#x8D77;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4F60;&#x53EA;&#x6709;&#x5728; <code>@/router/index.js</code> &#x4E0B;&#x9762;&#x914D;&#x7F6E;&#x5BF9;&#x5E94;&#x7684;&#x8DEF;&#x7531;&#xFF0C;&#x4FA7;&#x8FB9;&#x680F;&#x5C31;&#x80FD;&#x52A8;&#x6001;&#x7684;&#x751F;&#x6210;&#x4E86;&#x3002;&#x5927;&#x5927;&#x51CF;&#x8F7B;&#x4E86;&#x624B;&#x52A8;&#x91CD;&#x590D;&#x7F16;&#x8F91;&#x4FA7;&#x8FB9;&#x680F;&#x7684;&#x5DE5;&#x4F5C;&#x91CF;&#x3002;&#x5F53;&#x7136;&#x8FD9;&#x6837;&#x5C31;&#x9700;&#x8981;&#x5728;&#x914D;&#x7F6E;&#x8DEF;&#x7531;&#x7684;&#x65F6;&#x5019;&#x9075;&#x5FAA;&#x4E00;&#x4E9B;&#x7EA6;&#x5B9A;&#x7684;&#x89C4;&#x5219;&#x3002;</p>
<h2 id="&#x914D;&#x7F6E;&#x9879;">&#x914D;&#x7F6E;&#x9879;</h2>
<p>&#x9996;&#x5148;&#x6211;&#x4EEC;&#x4E86;&#x89E3;&#x4E00;&#x4E0B;&#x672C;&#x9879;&#x76EE;&#x914D;&#x7F6E;&#x8DEF;&#x7531;&#x65F6;&#x63D0;&#x4F9B;&#x4E86;&#x54EA;&#x4E9B;&#x914D;&#x7F6E;&#x9879;&#x3002;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// &#x5F53;&#x8BBE;&#x7F6E; true &#x7684;&#x65F6;&#x5019;&#x8BE5;&#x8DEF;&#x7531;&#x4E0D;&#x4F1A;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x51FA;&#x73B0; &#x5982;401&#xFF0C;login&#x7B49;&#x9875;&#x9762;&#xFF0C;&#x6216;&#x8005;&#x5982;&#x4E00;&#x4E9B;&#x7F16;&#x8F91;&#x9875;&#x9762;/edit/1</span>
hidden<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token comment">// (&#x9ED8;&#x8BA4; false)</span>

<span class="token comment">//&#x5F53;&#x8BBE;&#x7F6E; noRedirect &#x7684;&#x65F6;&#x5019;&#x8BE5;&#x8DEF;&#x7531;&#x5728;&#x9762;&#x5305;&#x5C51;&#x5BFC;&#x822A;&#x4E2D;&#x4E0D;&#x53EF;&#x88AB;&#x70B9;&#x51FB;</span>
redirect<span class="token operator">:</span> <span class="token string">&apos;noRedirect&apos;</span>

<span class="token comment">// &#x5F53;&#x4F60;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x4E0B;&#x9762;&#x7684; children &#x58F0;&#x660E;&#x7684;&#x8DEF;&#x7531;&#x5927;&#x4E8E;1&#x4E2A;&#x65F6;&#xFF0C;&#x81EA;&#x52A8;&#x4F1A;&#x53D8;&#x6210;&#x5D4C;&#x5957;&#x7684;&#x6A21;&#x5F0F;--&#x5982;&#x7EC4;&#x4EF6;&#x9875;&#x9762;</span>
<span class="token comment">// &#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x65F6;&#xFF0C;&#x4F1A;&#x5C06;&#x90A3;&#x4E2A;&#x5B50;&#x8DEF;&#x7531;&#x5F53;&#x505A;&#x6839;&#x8DEF;&#x7531;&#x663E;&#x793A;&#x5728;&#x4FA7;&#x8FB9;&#x680F;--&#x5982;&#x5F15;&#x5BFC;&#x9875;&#x9762;</span>
<span class="token comment">// &#x82E5;&#x4F60;&#x60F3;&#x4E0D;&#x7BA1;&#x8DEF;&#x7531;&#x4E0B;&#x9762;&#x7684; children &#x58F0;&#x660E;&#x7684;&#x4E2A;&#x6570;&#x90FD;&#x663E;&#x793A;&#x4F60;&#x7684;&#x6839;&#x8DEF;&#x7531;</span>
<span class="token comment">// &#x4F60;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E; alwaysShow: true&#xFF0C;&#x8FD9;&#x6837;&#x5B83;&#x5C31;&#x4F1A;&#x5FFD;&#x7565;&#x4E4B;&#x524D;&#x5B9A;&#x4E49;&#x7684;&#x89C4;&#x5219;&#xFF0C;&#x4E00;&#x76F4;&#x663E;&#x793A;&#x6839;&#x8DEF;&#x7531;</span>
alwaysShow<span class="token operator">:</span> <span class="token boolean">true</span>

name<span class="token operator">:</span> <span class="token string">&apos;router-name&apos;</span> <span class="token comment">// &#x8BBE;&#x5B9A;&#x8DEF;&#x7531;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x586B;&#x5199;&#x4E0D;&#x7136;&#x4F7F;&#x7528;&lt;keep-alive&gt;&#x65F6;&#x4F1A;&#x51FA;&#x73B0;&#x5404;&#x79CD;&#x95EE;&#x9898;</span>
meta<span class="token operator">:</span> <span class="token punctuation">{</span>
  roles<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&apos;admin&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;editor&apos;</span><span class="token punctuation">]</span> <span class="token comment">// &#x8BBE;&#x7F6E;&#x8BE5;&#x8DEF;&#x7531;&#x8FDB;&#x5165;&#x7684;&#x6743;&#x9650;&#xFF0C;&#x652F;&#x6301;&#x591A;&#x4E2A;&#x6743;&#x9650;&#x53E0;&#x52A0;</span>
  title<span class="token operator">:</span> <span class="token string">&apos;title&apos;</span> <span class="token comment">// &#x8BBE;&#x7F6E;&#x8BE5;&#x8DEF;&#x7531;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x548C;&#x9762;&#x5305;&#x5C51;&#x4E2D;&#x5C55;&#x793A;&#x7684;&#x540D;&#x5B57;</span>
  icon<span class="token operator">:</span> <span class="token string">&apos;svg-name&apos;</span> <span class="token comment">// &#x8BBE;&#x7F6E;&#x8BE5;&#x8DEF;&#x7531;&#x7684;&#x56FE;&#x6807;&#xFF0C;&#x652F;&#x6301; svg-class&#xFF0C;&#x4E5F;&#x652F;&#x6301; el-icon-x element-ui &#x7684; icon</span>
  noCache<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token comment">// &#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E3A;true&#xFF0C;&#x5219;&#x4E0D;&#x4F1A;&#x88AB; &lt;keep-alive&gt; &#x7F13;&#x5B58;(&#x9ED8;&#x8BA4; false)</span>
  breadcrumb<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token comment">//  &#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E3A;false&#xFF0C;&#x5219;&#x4E0D;&#x4F1A;&#x5728;breadcrumb&#x9762;&#x5305;&#x5C51;&#x4E2D;&#x663E;&#x793A;(&#x9ED8;&#x8BA4; true)</span>
  affix<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token comment">// &#x82E5;&#x679C;&#x8BBE;&#x7F6E;&#x4E3A;true&#xFF0C;&#x5B83;&#x5219;&#x4F1A;&#x56FA;&#x5B9A;&#x5728;tags-view&#x4E2D;(&#x9ED8;&#x8BA4; false)</span>

  <span class="token comment">// &#x5F53;&#x8DEF;&#x7531;&#x8BBE;&#x7F6E;&#x4E86;&#x8BE5;&#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x4F1A;&#x9AD8;&#x4EAE;&#x76F8;&#x5BF9;&#x5E94;&#x7684;&#x4FA7;&#x8FB9;&#x680F;&#x3002;</span>
  <span class="token comment">// &#x8FD9;&#x5728;&#x67D0;&#x4E9B;&#x573A;&#x666F;&#x975E;&#x5E38;&#x6709;&#x7528;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;&#x4E00;&#x4E2A;&#x6587;&#x7AE0;&#x7684;&#x5217;&#x8868;&#x9875;&#x8DEF;&#x7531;&#x4E3A;&#xFF1A;/article/list</span>
  <span class="token comment">// &#x70B9;&#x51FB;&#x6587;&#x7AE0;&#x8FDB;&#x5165;&#x6587;&#x7AE0;&#x8BE6;&#x60C5;&#x9875;&#xFF0C;&#x8FD9;&#x65F6;&#x5019;&#x8DEF;&#x7531;&#x4E3A;/article/1&#xFF0C;&#x4F46;&#x4F60;&#x60F3;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x9AD8;&#x4EAE;&#x6587;&#x7AE0;&#x5217;&#x8868;&#x7684;&#x8DEF;&#x7531;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x5982;&#x4E0B;&#x8BBE;&#x7F6E;</span>
  activeMenu<span class="token operator">:</span> <span class="token string">&apos;/article/list&apos;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><strong>&#x793A;&#x4F8B;&#xFF1A;</strong></p>
<pre class="language-"><code class="lang-js"><span class="token punctuation">{</span>
  path<span class="token operator">:</span> <span class="token string">&apos;/permission&apos;</span><span class="token punctuation">,</span>
  component<span class="token operator">:</span> Layout<span class="token punctuation">,</span>
  redirect<span class="token operator">:</span> <span class="token string">&apos;/permission/index&apos;</span><span class="token punctuation">,</span> <span class="token comment">//&#x91CD;&#x5B9A;&#x5411;&#x5730;&#x5740;&#xFF0C;&#x5728;&#x9762;&#x5305;&#x5C51;&#x4E2D;&#x70B9;&#x51FB;&#x4F1A;&#x91CD;&#x5B9A;&#x5411;&#x53BB;&#x7684;&#x5730;&#x5740;</span>
  hidden<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// &#x4E0D;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x7EBF;&#x4E0A;</span>
  alwaysShow<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">//&#x4E00;&#x76F4;&#x663E;&#x793A;&#x6839;&#x8DEF;&#x7531;</span>
  meta<span class="token operator">:</span> <span class="token punctuation">{</span> roles<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&apos;admin&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;editor&apos;</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">//&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x6839;&#x8DEF;&#x7531;&#x8BBE;&#x7F6E;&#x6743;&#x9650;&#xFF0C;&#x8FD9;&#x6837;&#x5B83;&#x4E0B;&#x9762;&#x6240;&#x4EE5;&#x7684;&#x5B50;&#x8DEF;&#x7531;&#x90FD;&#x7EE7;&#x627F;&#x4E86;&#x8FD9;&#x4E2A;&#x6743;&#x9650;</span>
  children<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
    path<span class="token operator">:</span> <span class="token string">&apos;index&apos;</span><span class="token punctuation">,</span>
    <span class="token function-variable function">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;permission/index&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    name<span class="token operator">:</span> <span class="token string">&apos;permission&apos;</span><span class="token punctuation">,</span>
    meta<span class="token operator">:</span> <span class="token punctuation">{</span>
      title<span class="token operator">:</span> <span class="token string">&apos;permission&apos;</span><span class="token punctuation">,</span>
      icon<span class="token operator">:</span> <span class="token string">&apos;lock&apos;</span><span class="token punctuation">,</span> <span class="token comment">//&#x56FE;&#x6807;</span>
      roles<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&apos;admin&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;editor&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token comment">//&#x6216;&#x8005;&#x4F60;&#x53EF;&#x4EE5;&#x7ED9;&#x6BCF;&#x4E00;&#x4E2A;&#x5B50;&#x8DEF;&#x7531;&#x8BBE;&#x7F6E;&#x81EA;&#x5DF1;&#x7684;&#x6743;&#x9650;</span>
      noCache<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token comment">// &#x4E0D;&#x4F1A;&#x88AB; &lt;keep-alive&gt; &#x7F13;&#x5B58;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x8DEF;&#x7531;">&#x8DEF;&#x7531;</h2>
<p>&#x8FD9;&#x91CC;&#x7684;&#x8DEF;&#x7531;&#x5206;&#x4E3A;&#x4E24;&#x79CD;&#xFF0C;<code>constantRoutes</code> &#x548C; <code>asyncRoutes</code>&#x3002;</p>
<p><strong>constantRoutes&#xFF1A;</strong> &#x4EE3;&#x8868;&#x90A3;&#x4E9B;&#x4E0D;&#x9700;&#x8981;&#x52A8;&#x6001;&#x5224;&#x65AD;&#x6743;&#x9650;&#x7684;&#x8DEF;&#x7531;&#xFF0C;&#x5982;&#x767B;&#x5F55;&#x9875;&#x3001;404&#x3001;&#x7B49;&#x901A;&#x7528;&#x9875;&#x9762;&#x3002;</p>
<p><strong>asyncRoutes&#xFF1A;</strong> &#x4EE3;&#x8868;&#x90A3;&#x4E9B;&#x9700;&#x6C42;&#x52A8;&#x6001;&#x5224;&#x65AD;&#x6743;&#x9650;&#x5E76;&#x901A;&#x8FC7; <code>addRoutes</code> &#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x7684;&#x9875;&#x9762;&#x3002;</p>
<p>&#x5177;&#x4F53;&#x7684;&#x4F1A;&#x5728; <a href="https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials/permission.html" target="_blank">&#x6743;&#x9650;&#x9A8C;&#x8BC1;</a> &#x9875;&#x9762;&#x4ECB;&#x7ECD;&#x3002;</p>
<p>TIP</p>
<p>&#x8FD9;&#x91CC;&#x6240;&#x6709;&#x7684;&#x8DEF;&#x7531;&#x9875;&#x9762;&#x90FD;&#x4F7F;&#x7528; <code>&#x8DEF;&#x7531;&#x61D2;&#x52A0;&#x8F7D;</code> &#x4E86; &#xFF0C;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x89C1;<a href="https://panjiachen.github.io/vue-element-admin-site/zh/guide/advanced/lazy-loading.html" target="_blank">&#x6587;&#x6863;</a></p>
<p>&#x5982;&#x679C;&#x4F60;&#x60F3;&#x4E86;&#x89E3;&#x66F4;&#x591A;&#x5173;&#x4E8E; browserHistory &#x548C; hashHistory&#xFF0C;&#x8BF7;&#x53C2;&#x770B; <a href="https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials/deploy.html" target="_blank">&#x6784;&#x5EFA;&#x548C;&#x53D1;&#x5E03;</a>&#x3002;</p>
<p>&#x5176;&#x5B83;&#x7684;&#x914D;&#x7F6E;&#x548C; <a href="https://router.vuejs.org/zh-cn/" target="_blank">vue-router</a> &#x5B98;&#x65B9;&#x5E76;&#x6CA1;&#x6709;&#x533A;&#x522B;&#xFF0C;&#x81EA;&#x884C;&#x67E5;&#x770B;&#x6587;&#x6863;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#x4E8B;&#x9879;</p>
<p>&#x5982;&#x679C;&#x8FD9;&#x91CC;&#x6709;&#x4E00;&#x4E2A;&#x9700;&#x8981;&#x975E;&#x5E38;&#x6CE8;&#x610F;&#x7684;&#x5730;&#x65B9;&#x5C31;&#x662F; <code>404</code> &#x9875;&#x9762;&#x4E00;&#x5B9A;&#x8981;&#x6700;&#x540E;&#x52A0;&#x8F7D;&#xFF0C;&#x5982;&#x679C;&#x653E;&#x5728; constantRoutes &#x4E00;&#x540C;&#x58F0;&#x660E;&#x4E86; <code>404</code> &#xFF0C;&#x540E;&#x9762;&#x7684;&#x6240;&#x4EE5;&#x9875;&#x9762;&#x90FD;&#x4F1A;&#x88AB;&#x62E6;&#x622A;&#x5230;<code>404</code> &#xFF0C;&#x8BE6;&#x7EC6;&#x7684;&#x95EE;&#x9898;&#x89C1; <a href="https://github.com/vuejs/vue-router/issues/1176" target="_blank">addRoutes when you&apos;ve got a wildcard route for 404s does not work</a></p>
<h2 id="&#x4FA7;&#x8FB9;&#x680F;">&#x4FA7;&#x8FB9;&#x680F;</h2>
<p>&#x672C;&#x9879;&#x76EE;&#x4FA7;&#x8FB9;&#x680F;&#x4E3B;&#x8981;&#x57FA;&#x4E8E; <code>element-ui</code> &#x7684; <code>el-menu</code> &#x6539;&#x9020;&#x3002;</p>
<p>&#x524D;&#x9762;&#x4E5F;&#x4ECB;&#x7ECD;&#x4E86;&#xFF0C;&#x4FA7;&#x8FB9;&#x680F;&#x662F;&#x901A;&#x8FC7;&#x8BFB;&#x53D6;&#x8DEF;&#x7531;&#x5E76;&#x7ED3;&#x5408;&#x6743;&#x9650;&#x5224;&#x65AD;&#x800C;&#x52A8;&#x6001;&#x751F;&#x6210;&#x7684;&#xFF0C;&#x800C;&#x4E14;&#x8FD8;&#x9700;&#x8981;&#x652F;&#x6301;&#x8DEF;&#x7531;&#x65E0;&#x9650;&#x5D4C;&#x5957;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x91CC;&#x8FD8;&#x4F7F;&#x7528;&#x5230;&#x4E86;&#x9012;&#x5F52;&#x7EC4;&#x4EF6;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x5730;&#x5740;</p>
<p><a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/layout/components/Sidebar" target="_blank">@/layout/components/Sidebar</a></p>
<p>&#x8FD9;&#x91CC;&#x540C;&#x65F6;&#x4E5F;&#x6539;&#x9020;&#x4E86; <code>element-ui</code> &#x9ED8;&#x8BA4;&#x4FA7;&#x8FB9;&#x680F;&#x4E0D;&#x5C11;&#x7684;&#x6837;&#x5F0F;&#xFF0C;&#x6240;&#x6709;&#x7684; css &#x90FD;&#x53EF;&#x4EE5;&#x5728; <a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/styles/sidebar.scss" target="_blank">@/styles/sidebar.scss</a> &#x4E2D;&#x627E;&#x5230;&#xFF0C;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x9700;&#x6C42;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x3002;</p>
<p><strong>&#x8FD9;&#x91CC;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4E00;&#x4E0B;</strong>&#xFF0C;&#x4E00;&#x822C;&#x4FA7;&#x8FB9;&#x680F;&#x6709;&#x4E24;&#x79CD;&#x5F62;&#x5F0F;&#x5373;&#xFF1A;<code>submenu</code> &#x548C; &#x76F4;&#x63A5; <code>el-menu-item</code>&#x3002; &#x4E00;&#x4E2A;&#x662F;&#x5D4C;&#x5957;&#x5B50;&#x83DC;&#x5355;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x5219;&#x662F;&#x76F4;&#x63A5;&#x4E00;&#x4E2A;&#x94FE;&#x63A5;&#x3002;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</p>
<p><img src="https://panjiachen.gitee.io/gitee-cdn/vue-element-admin-site/e94739d6-d701-45c8-8c6e-0f4bb10c3b46.png" alt="img"></p>
<p>&#x5728; <code>Sidebar</code> &#x4E2D;&#x5DF2;&#x7ECF;&#x5E2E;&#x4F60;&#x505A;&#x4E86;&#x5224;&#x65AD;&#xFF0C;&#x5F53;&#x4F60;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x4E0B;&#x9762;&#x7684; <code>children</code> &#x58F0;&#x660E;&#x7684;&#x8DEF;&#x7531;&#x5927;&#x4E8E;&gt;1 &#x4E2A;&#x65F6;&#xFF0C;&#x81EA;&#x52A8;&#x4F1A;&#x53D8;&#x6210;&#x5D4C;&#x5957;&#x7684;&#x6A21;&#x5F0F;&#x3002;&#x5982;&#x679C;&#x5B50;&#x8DEF;&#x7531;&#x6B63;&#x597D;&#x7B49;&#x4E8E;&#x4E00;&#x4E2A;&#x5C31;&#x4F1A;&#x9ED8;&#x8BA4;&#x5C06;&#x5B50;&#x8DEF;&#x7531;&#x4F5C;&#x4E3A;&#x6839;&#x8DEF;&#x7531;&#x663E;&#x793A;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x4E2D;&#xFF0C;&#x82E5;&#x4E0D;&#x60F3;&#x8FD9;&#x6837;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8BBE;&#x7F6E;&#x5728;&#x6839;&#x8DEF;&#x7531;&#x4E2D;&#x8BBE;&#x7F6E;<code>alwaysShow: true</code>&#x6765;&#x53D6;&#x6D88;&#x8FD9;&#x4E00;&#x7279;&#x6027;&#x3002;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// No submenu, because children.length===1</span>
<span class="token punctuation">{</span>
  path<span class="token operator">:</span> <span class="token string">&apos;/icon&apos;</span><span class="token punctuation">,</span>
  component<span class="token operator">:</span> Layout<span class="token punctuation">,</span>
  children<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
    path<span class="token operator">:</span> <span class="token string">&apos;index&apos;</span><span class="token punctuation">,</span>
    <span class="token function-variable function">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;svg-icons/index&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    name<span class="token operator">:</span> <span class="token string">&apos;icons&apos;</span><span class="token punctuation">,</span>
    meta<span class="token operator">:</span> <span class="token punctuation">{</span> title<span class="token operator">:</span> <span class="token string">&apos;icons&apos;</span><span class="token punctuation">,</span> icon<span class="token operator">:</span> <span class="token string">&apos;icon&apos;</span> <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>

<span class="token comment">// Has submenu, because children.length&gt;=1</span>
<span class="token punctuation">{</span>
  path<span class="token operator">:</span> <span class="token string">&apos;/components&apos;</span><span class="token punctuation">,</span>
  component<span class="token operator">:</span> Layout<span class="token punctuation">,</span>
  name<span class="token operator">:</span> <span class="token string">&apos;component-demo&apos;</span><span class="token punctuation">,</span>
  meta<span class="token operator">:</span> <span class="token punctuation">{</span>
    title<span class="token operator">:</span> <span class="token string">&apos;components&apos;</span><span class="token punctuation">,</span>
    icon<span class="token operator">:</span> <span class="token string">&apos;component&apos;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  children<span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span> path<span class="token operator">:</span> <span class="token string">&apos;tinymce&apos;</span><span class="token punctuation">,</span> <span class="token function-variable function">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;components-demo/tinymce&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> name<span class="token operator">:</span> <span class="token string">&apos;tinymce-demo&apos;</span><span class="token punctuation">,</span> meta<span class="token operator">:</span> <span class="token punctuation">{</span> title<span class="token operator">:</span> <span class="token string">&apos;tinymce&apos;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span> path<span class="token operator">:</span> <span class="token string">&apos;markdown&apos;</span><span class="token punctuation">,</span> <span class="token function-variable function">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">&apos;components-demo/markdown&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> name<span class="token operator">:</span> <span class="token string">&apos;markdown-demo&apos;</span><span class="token punctuation">,</span> meta<span class="token operator">:</span> <span class="token punctuation">{</span> title<span class="token operator">:</span> <span class="token string">&apos;markdown&apos;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<p>unique-opened</p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x5728;<a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/layout/components/Sidebar/index.vue" target="_blank">Sidebar/index.vue</a>&#x4E2D;&#x8BBE;&#x7F6E;<code>unique-opened</code>&#x6765;&#x63A7;&#x5236;&#x4FA7;&#x8FB9;&#x680F;&#xFF0C;&#x662F;&#x5426;&#x53EA;&#x4FDD;&#x6301;&#x4E00;&#x4E2A;&#x5B50;&#x83DC;&#x5355;&#x7684;&#x5C55;&#x5F00;&#x3002;</p>
<h2 id="&#x591A;&#x7EA7;&#x76EE;&#x5F55;&#x5D4C;&#x5957;&#x8DEF;&#x7531;">&#x591A;&#x7EA7;&#x76EE;&#x5F55;(&#x5D4C;&#x5957;&#x8DEF;&#x7531;)</h2>
<p>&#x5982;&#x679C;&#x4F60;&#x7684;&#x8DEF;&#x7531;&#x662F;&#x591A;&#x7EA7;&#x76EE;&#x5F55;&#xFF0C;&#x5982;&#x672C;&#x9879;&#x76EE; <a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/views/nested" target="_blank">@/views/nested</a> &#x90A3;&#x6837;&#xFF0C; &#x6709;&#x4E09;&#x7EA7;&#x8DEF;&#x7531;&#x5D4C;&#x5957;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;<strong>&#x4E0D;&#x8981;&#x5FD8;&#x8BB0;&#x8FD8;&#x8981;&#x624B;&#x52A8;&#x5728;&#x4E8C;&#x7EA7;&#x76EE;&#x5F55;&#x7684;&#x6839;&#x6587;&#x4EF6;&#x4E0B;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A; <code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>router-view</span><span class="token punctuation">&gt;</span></span></code></strong>&#x3002;</p>
<pre class="language-"><code class="lang-html"> <span class="token comment">&lt;!-- &#x7236;&#x7EA7;&#x8DEF;&#x7531;&#x7EC4;&#x4EF6;  --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token comment">&lt;!-- xxx html &#x5185;&#x5BB9;  --&gt;</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>router-view</span> <span class="token punctuation">/&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>&#x5982;&#xFF1A;<a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/nested/menu1/index.vue" target="_blank">@/views/nested/menu1/index.vue</a>&#xFF0C;&#x539F;&#x5219;&#x4E0A;&#x6709;&#x591A;&#x5C11;&#x7EA7;&#x8DEF;&#x7531;&#x5D4C;&#x5957;&#x5C31;&#x9700;&#x8981;&#x591A;&#x5C11;&#x4E2A;<code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>router-view</span><span class="token punctuation">&gt;</span></span></code>&#x3002;</p>
<p><img src="https://panjiachen.gitee.io/gitee-cdn/vue-element-admin-site/9459de62-64d0-4819-9730-daf3f9889018.png" alt="img"></p>
<h2 id="&#x70B9;&#x51FB;&#x4FA7;&#x8FB9;&#x680F;-&#x5237;&#x65B0;&#x5F53;&#x524D;&#x8DEF;&#x7531;">&#x70B9;&#x51FB;&#x4FA7;&#x8FB9;&#x680F; &#x5237;&#x65B0;&#x5F53;&#x524D;&#x8DEF;&#x7531;</h2>
<p>&#x5728;&#x7528; spa(&#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;) &#x8FD9;&#x79CD;&#x5F00;&#x53D1;&#x6A21;&#x5F0F;&#x4E4B;&#x524D;&#xFF0C;&#x7528;&#x6237;&#x6BCF;&#x6B21;&#x70B9;&#x51FB;&#x4FA7;&#x8FB9;&#x680F;&#x90FD;&#x4F1A;&#x91CD;&#x65B0;&#x8BF7;&#x6C42;&#x8FD9;&#x4E2A;&#x9875;&#x9762;&#xFF0C;&#x7528;&#x6237;&#x6E10;&#x6E10;&#x517B;&#x6210;&#x4E86;&#x70B9;&#x51FB;&#x4FA7;&#x8FB9;&#x680F;&#x5F53;&#x524D;&#x8DEF;&#x7531;&#x6765;&#x5237;&#x65B0; view &#x7684;&#x4E60;&#x60EF;&#x3002;&#x4F46;&#x73B0;&#x5728; spa &#x5C31;&#x4E0D;&#x4E00;&#x6837;&#x4E86;&#xFF0C;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x5F53;&#x524D;&#x9AD8;&#x4EAE;&#x7684;&#x8DEF;&#x7531;&#x5E76;&#x4E0D;&#x4F1A;&#x5237;&#x65B0; view&#xFF0C;&#x56E0;&#x4E3A; vue-router &#x4F1A;&#x62E6;&#x622A;&#x4F60;&#x7684;&#x8DEF;&#x7531;&#xFF0C;&#x5B83;&#x5224;&#x65AD;&#x4F60;&#x7684; url &#x5E76;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x53D8;&#x5316;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x4E0D;&#x4F1A;&#x89E6;&#x53D1;&#x4EFB;&#x4F55;&#x94A9;&#x5B50;&#x6216;&#x8005;&#x662F; view &#x7684;&#x53D8;&#x5316;&#x3002;<a href="https://github.com/vuejs/vue-router/issues/296" target="_blank">issue</a> &#x5730;&#x5740;&#xFF0C;&#x793E;&#x533A;&#x4E5F;&#x5BF9;&#x8BE5;&#x95EE;&#x9898;&#x5C55;&#x5F00;&#x4E86;&#x6FC0;&#x70C8;&#x8BA8;&#x8BBA;&#x3002;</p>
<p><img src="https://panjiachen.gitee.io/gitee-cdn/vue-element-admin-site/5d0b0391-ea6a-45f2-943e-aff5dbe74d12.png" alt="img"></p>
<p>&#x5C24;&#x5927;&#x672C;&#x6765;&#x4E5F;&#x8BF4;&#x8981;&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6765;&#x5F3A;&#x5237; view&#xFF0C;&#x4F46;&#x540E;&#x6765;&#x4ED6;&#x53C8;&#x6539;&#x53D8;&#x4E86;&#x5FC3;&#x610F;/(&#x3112; o &#x3112;)/~~&#x3002;&#x4F46;&#x9700;&#x6C42;&#x5C31;&#x6446;&#x5728;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x8BE5;&#x600E;&#x4E48;&#x529E;&#x5462;&#xFF1F;&#x4ED6;&#x8BF4;&#x4E86;&#x4E0D;&#x6539;&#x53D8; current URL &#x5C31;&#x4E0D;&#x4F1A;&#x89E6;&#x53D1;&#x4EFB;&#x4F55;&#x4E1C;&#x897F;&#xFF0C;&#x90A3;&#x6211;&#x53EF;&#x4E0D;&#x53EF;&#x4EE5;&#x5F3A;&#x884C;&#x89E6;&#x53D1;&#x4F60;&#x7684; hook &#x5462;&#xFF1F;&#x4E0A;&#x6709;&#x653F;&#x7B56;&#xFF0C; &#x4E0B;&#x6709;&#x5BF9;&#x7B56;&#x6211;&#x4EEC;&#x53D8;&#x7740;&#x82B1;&#x6765; hack&#x3002;&#x65B9;&#x6CD5;&#x4E5F;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x901A;&#x8FC7;&#x4E0D;&#x65AD;&#x6539;&#x53D8; url &#x7684; query &#x6765;&#x89E6;&#x53D1; view &#x7684;&#x53D8;&#x5316;&#x3002;&#x6211;&#x4EEC;&#x76D1;&#x542C;&#x4FA7;&#x8FB9;&#x680F;&#x6BCF;&#x4E2A; link &#x7684; click &#x4E8B;&#x4EF6;&#xFF0C;&#x6BCF;&#x6B21;&#x70B9;&#x51FB;&#x90FD;&#x7ED9; router push &#x4E00;&#x4E2A;&#x4E0D;&#x4E00;&#x6837;&#x7684; query &#x6765;&#x786E;&#x4FDD;&#x4F1A;&#x91CD;&#x65B0;&#x5237;&#x65B0; view&#x3002;</p>
<pre class="language-"><code class="lang-js"><span class="token function">clickLink</span><span class="token punctuation">(</span><span class="token parameter">path</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>$router<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    path<span class="token punctuation">,</span>
    query<span class="token operator">:</span> <span class="token punctuation">{</span>
      t<span class="token operator">:</span> <span class="token operator">+</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">//&#x4FDD;&#x8BC1;&#x6BCF;&#x6B21;&#x70B9;&#x51FB;&#x8DEF;&#x7531;&#x7684;query&#x9879;&#x90FD;&#x662F;&#x4E0D;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x786E;&#x4FDD;&#x4F1A;&#x91CD;&#x65B0;&#x5237;&#x65B0;view</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>ps:&#x4E0D;&#x8981;&#x5FD8;&#x4E86;&#x5728; <code>router-view</code> &#x52A0;&#x4E0A;&#x4E00;&#x4E2A;&#x7279;&#x5B9A;&#x552F;&#x4E00;&#x7684; <code>key</code>&#xFF0C;&#x5982; <code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>router-view</span> <span class="token attr-name">:key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>$route.path<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>router-view</span><span class="token punctuation">&gt;</span></span></code>&#xFF0C; &#x4F46;&#x8FD9;&#x4E5F;&#x6709;&#x4E00;&#x4E2A;&#x5F0A;&#x7AEF;&#x5C31;&#x662F; url &#x540E;&#x9762;&#x6709;&#x4E00;&#x4E2A;&#x5F88;&#x96BE;&#x770B;&#x7684; <code>query</code> &#x540E;&#x7F00;&#x5982; <code>xxx.com/article/list?t=1496832345025</code></p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x4ECE;&#x524D;&#x9762;&#x7684; issue &#x4E2D;&#x77E5;&#x9053;&#x8FD8;&#x6709;&#x5F88;&#x591A;&#x5176;&#x5B83;&#x65B9;&#x6848;&#x3002;&#x6211;&#x672C;&#x4EBA;&#x5728;&#x516C;&#x53F8;&#x9879;&#x76EE;&#x4E2D;&#xFF0C;&#x73B0;&#x5728;&#x91C7;&#x53D6;&#x7684;&#x65B9;&#x6848;&#x662F;&#x5224;&#x65AD;&#x5F53;&#x524D;&#x70B9;&#x51FB;&#x7684;&#x83DC;&#x5355;&#x8DEF;&#x7531;&#x548C;&#x5F53;&#x524D;&#x7684;&#x8DEF;&#x7531;&#x662F;&#x5426;&#x4E00;&#x81F4;&#xFF0C;&#x4F46;&#x4E00;&#x81F4;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x5148;&#x8DF3;&#x8F6C;&#x5230;&#x4E00;&#x4E2A;&#x4E13;&#x95E8; Redirect &#x7684;&#x9875;&#x9762;&#xFF0C;&#x5B83;&#x4F1A;&#x5C06;&#x8DEF;&#x7531;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x6211;&#x60F3;&#x53BB;&#x7684;&#x9875;&#x9762;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x8D77;&#x5230;&#x4E86;&#x5237;&#x65B0;&#x7684;&#x6548;&#x679C;&#x4E86;&#x3002;</p>
<p><strong>&#x76F8;&#x5173;&#x4F8B;&#x5B50;</strong></p>
<p><img src="https://panjiachen.gitee.io/gitee-cdn/vue-element-admin-site/0dd7f78b-0fb5-4c7d-8236-cee78f960984.jpg" alt="img"></p>
<p>&#x70B9;&#x51FB;&#x56FE;&#x7247;&#x6240;&#x793A;&#x7684;&#x5168;&#x5C40; size &#x5927;&#x5C0F;&#x5207;&#x6362;&#x6309;&#x94AE;&#xFF0C;&#x4F60;&#x4F1A;&#x53D1;&#x73B0; &#x9875;&#x9762; <code>app-main</code>&#x533A;&#x57DF;&#x8FDB;&#x884C;&#x4E86;&#x5237;&#x65B0;&#x3002;&#x5B83;&#x5C31;&#x662F;&#x8FD0;&#x7528;&#x4E86;&#x91CD;&#x5B9A;&#x5411;&#x5230; <code>Redirect</code>&#x9875;&#x9762;&#x4E4B;&#x540E;&#x518D;&#x91CD;&#x5B9A;&#x5411;&#x56DE;&#x539F;&#x59CB;&#x9875;&#x9762;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x70B9;&#x51FB;&#x7684;&#x65F6;&#x5019;&#x91CD;&#x5B9A;&#x5411;&#x9875;&#x9762;&#x81F3; <code>/redirect</code></p>
<pre class="language-"><code class="lang-js"><span class="token keyword">const</span> <span class="token punctuation">{</span> fullPath <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>$route
<span class="token keyword">this</span><span class="token punctuation">.</span>$router<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  path<span class="token operator">:</span> <span class="token string">&apos;/redirect&apos;</span> <span class="token operator">+</span> fullPath
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<p><code>redirect</code> &#x9875;&#x9762;&#x5728;&#x91CD;&#x5B9A;&#x5411;&#x56DE;&#x539F;&#x59CB;&#x9875;&#x9762;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// redirect.vue</span>
<span class="token comment">// https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/redirect/index.vue</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token function">beforeCreate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> params<span class="token punctuation">,</span> query <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>$route
    <span class="token keyword">const</span> <span class="token punctuation">{</span> path <span class="token punctuation">}</span> <span class="token operator">=</span> params
    <span class="token keyword">this</span><span class="token punctuation">.</span>$router<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token punctuation">{</span> path<span class="token operator">:</span> <span class="token string">&apos;/&apos;</span> <span class="token operator">+</span> path<span class="token punctuation">,</span> query <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function-variable function">render</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">h</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">h</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// avoid warning message</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x9762;&#x5305;&#x5C51;">&#x9762;&#x5305;&#x5C51;</h2>
<p>&#x672C;&#x9879;&#x76EE;&#x4E2D;&#x4E5F;&#x5C01;&#x88C5;&#x4E86;&#x4E00;&#x4E2A;&#x9762;&#x5305;&#x5C51;&#x5BFC;&#x822A;&#xFF0C;&#x5B83;&#x4E5F;&#x662F;&#x901A;&#x8FC7; <code>watch $route</code> &#x53D8;&#x5316;&#x52A8;&#x6001;&#x751F;&#x6210;&#x7684;&#x3002;&#x5B83;&#x548C; menu &#x4E5F;&#x4E00;&#x6837;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E4B;&#x524D;&#x90A3;&#x4E9B;&#x914D;&#x7F6E;&#x9879;&#x63A7;&#x5236;&#x4E00;&#x4E9B;&#x8DEF;&#x7531;&#x5728;&#x9762;&#x5305;&#x5C51;&#x4E2D;&#x7684;&#x5C55;&#x73B0;&#x3002;&#x5927;&#x5BB6;&#x4E5F;&#x53EF;&#x4EE5;&#x7ED3;&#x5408;&#x81EA;&#x5DF1;&#x7684;&#x4E1A;&#x52A1;&#x9700;&#x6C42;&#x589E;&#x6539;&#x8FD9;&#x4E9B;&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;&#x3002;&#x6BD4;&#x5982;&#x53EF;&#x4EE5;&#x5728;&#x8DEF;&#x7531;&#x4E2D;&#x58F0;&#x660E;<code>breadcrumb:false</code>&#xFF0C;&#x8BA9;&#x5176;&#x4E0D;&#x5728; breadcrumb &#x9762;&#x5305;&#x5C51;&#x663E;&#x793A;&#x3002;</p>
<p><img src="https://panjiachen.gitee.io/gitee-cdn/vue-element-admin-site/4c60b3fc-febd-4e22-9150-724dcbd25a8e.gif" alt="img"></p>
<p>&#x4EE3;&#x7801;&#x5730;&#x5740;</p>
<p><a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/components/Breadcrumb/index.vue" target="_blank">@/components/Breadcrumb</a></p>
<h2 id="&#x4FA7;&#x8FB9;&#x680F;&#x6EDA;&#x52A8;&#x95EE;&#x9898;">&#x4FA7;&#x8FB9;&#x680F;&#x6EDA;&#x52A8;&#x95EE;&#x9898;</h2>
<p>&#x4E4B;&#x524D;&#x7248;&#x672C;&#x7684;&#x6EDA;&#x52A8;&#x90FD;&#x662F;&#x7528; css &#x6765;&#x505A;&#x5904;&#x7406;&#x7684;</p>
<pre class="language-"><code class="lang-css"><span class="token property">overflow-y</span><span class="token punctuation">:</span> scroll<span class="token selector">;

::-webkit-scrollbar</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> none<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x9996;&#x5148;&#x8FD9;&#x6837;&#x5199;&#x4F1A;&#x6709;&#x517C;&#x5BB9;&#x6027;&#x95EE;&#x9898;&#xFF0C;&#x5728;&#x706B;&#x72D0;&#x6216;&#x8005;&#x5176;&#x5B83;&#x4F4E;&#x7248;&#x672C;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x90FD;&#x4F1A;&#x6BD4;&#x8F83;&#x4E0D;&#x7F8E;&#x89C2;&#x3002;&#x5176;&#x6B21;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x6536;&#x8D77;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x53D7;&#x9650;&#x4E8E; <code>element-ui</code>&#x7684; <code>menu</code> &#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF0C;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x8BE5;&#x65B9;&#x5F0F;&#x6765;&#x5904;&#x7406;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#x73B0;&#x7248;&#x672C;&#x4E2D;&#x4F7F;&#x7528;&#x4E86; <code>el-scrollbar</code> &#x6765;&#x5904;&#x7406;&#x4FA7;&#x8FB9;&#x680F;&#x6EDA;&#x52A8;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x5730;&#x5740;</p>
<p><a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/layout/components/Sidebar/index.vue" target="_blank">@/layout/components/Sidebar</a></p>
<h2 id="&#x4FA7;&#x8FB9;&#x680F;-&#x5916;&#x94FE;-v382">&#x4FA7;&#x8FB9;&#x680F; &#x5916;&#x94FE; v3.8.2+</h2>
<p>&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x4FA7;&#x8FB9;&#x680F;&#x4E2D;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x5916;&#x94FE;&#xFF0C;&#x53EA;&#x8981;&#x4F60;&#x5728; <code>path</code> &#x4E2D;&#x586B;&#x5199;&#x4E86;&#x5408;&#x6CD5;&#x7684; url &#x8DEF;&#x5F84;&#xFF0C;&#x5F53;&#x4F60;&#x70B9;&#x51FB;&#x4FA7;&#x8FB9;&#x680F;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x5E2E;&#x4F60;&#x65B0;&#x5F00;&#x8FD9;&#x4E2A;&#x9875;&#x9762;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;path&quot;</span><span class="token operator">:</span> <span class="token string">&quot;external-link&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;component&quot;</span><span class="token operator">:</span> Layout<span class="token punctuation">,</span>
  <span class="token property">&quot;children&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;path&quot;</span><span class="token operator">:</span> <span class="token string">&quot;https://github.com/PanJiaChen/vue-element-admin&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;meta&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">&quot;title&quot;</span><span class="token operator">:</span> <span class="token string">&quot;externalLink&quot;</span><span class="token punctuation">,</span> <span class="token property">&quot;icon&quot;</span><span class="token operator">:</span> <span class="token string">&quot;link&quot;</span> <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x4FA7;&#x8FB9;&#x680F;&#x9ED8;&#x8BA4;&#x5C55;&#x5F00;">&#x4FA7;&#x8FB9;&#x680F;&#x9ED8;&#x8BA4;&#x5C55;&#x5F00;</h2>
<p>&#x67D0;&#x4E9B;&#x573A;&#x666F;&#x4E0B;&#xFF0C;&#x7528;&#x6237;&#x9700;&#x8981;&#x9ED8;&#x8BA4;&#x5C55;&#x5F00;&#x4FA7;&#x8FB9;&#x680F;&#x7684;&#x67D0;&#x4E9B;<code>sub-menu</code>&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;</p>
<p><img src="https://panjiachen.github.io/vue-element-admin-site/images/default-openeds.jpg" alt="default-openeds.jpg"></p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>default-openeds</code>&#x6765;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#xFF0C;&#x9996;&#x5148;&#x627E;&#x5230; <a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/layout/components/Sidebar/index.vue" target="_blank">&#x4FA7;&#x8FB9;&#x680F;&#x4EE3;&#x7801;</a></p>
<pre class="language-"><code class="lang-html"> &lt;el-menu
        :default-openeds=&quot;[&apos;/example&apos;,&apos;/nested&apos;]&quot; // &#x6DFB;&#x52A0;&#x672C;&#x884C;&#x4EE3;&#x7801;
        :default-active=&quot;activeMenu&quot;
        :collapse=&quot;isCollapse&quot;
        :background-color=&quot;variables.menuBg&quot;
        :text-color=&quot;variables.menuText&quot;
        :unique-opened=&quot;false&quot;
        :active-text-color=&quot;variables.menuActiveText&quot;
        :collapse-transition=&quot;false&quot;
        mode=&quot;vertical&quot;
      &gt;
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>sidebar-item</span> <span class="token attr-name">v-for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>route in permission_routes<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>route.path<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:item</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>route<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:base-path</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>route.path<span class="token punctuation">&quot;</span></span> <span class="token punctuation">/&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-menu</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p><strong>&#x6CE8;&#x610F; :default-openeds=&quot;[&apos;/example&apos;,&apos;/nested&apos;]&quot; &#x91CC;&#x9762;&#x586B;&#x5199;&#x7684;&#x662F; submenu &#x7684; route-path</strong></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="webpack.html" class="navigation navigation-prev " aria-label="Previous page: Webpack">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="env.html" class="navigation navigation-next " aria-label="Next page: 环境变量">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"路由和侧边栏","level":"1.5","depth":1,"next":{"title":"环境变量","level":"1.6","depth":1,"path":"src/env.md","ref":"src/env.md","articles":[]},"previous":{"title":"Webpack","level":"1.4","depth":1,"path":"src/webpack.md","ref":"src/webpack.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","-lunr","-search","search-pro","-highlight","prism","livereload"],"styles":{"website":"index.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"expandable-chapters":{},"search-pro":{},"livereload":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Gj","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"introduce","language":"zh-hans","gitbook":"3.2.3","description":"项目搭建、规范、使用示例介绍"},"file":{"path":"src/router.md","mtime":"2020-07-29T03:29:53.821Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-29T07:02:36.580Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

